<?php

class UserInstall
{

	private $_config = array(
		'name' => 'user',
		'title' => 'User module',
		'dependencies' => array(
			'notification'
		),
		'import' => array(
			'application.modules.user.UserModule',
			'application.modules.user.models.User',
			'application.modules.user.components.UserIdentity',
		)
	);
	
	public function config()
	{
		return $this->_config;
	}

	public function install()
	{
		$sql = "DROP TABLE IF EXISTS {{users}};";
		Yii::app()->db->createCommand($sql)->execute();

		$sql="
	CREATE TABLE IF NOT EXISTS {{users}} (
	  `id` int(11) NOT NULL AUTO_INCREMENT,
	  `active` tinyint(1) NOT NULL,
	  `fname` varchar(32) NOT NULL,
	  `sname` varchar(32) NOT NULL,
	  `username` varchar(128) NOT NULL,
	  `password` varchar(128) NOT NULL,
	  `salt` varchar(128) NOT NULL,
	  `email` varchar(128) NOT NULL,
	  `isAdmin` tinyint(1) NOT NULL DEFAULT '0',
	  `creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	  PRIMARY KEY (`id`)
	) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
		Yii::app()->db->createCommand($sql)->execute();

	}

	public function uninstall()
	{
		Yii::app()->db->createCommand()->dropTable('{{users}}');
	}
}